// 未登录重定向mixin
export const adminRedirectionMixin = {
  created () { 
    const token = uni.getStorageSync('token')
    if (!token) {
      uni.reLaunch({
        url: '/pages/login/login',
      })
    } else {
      const userInfo = uni.getStorageSync('user')
      if (userInfo && userInfo.role !== 0) {
        uni.reLaunch({
          url: '/pages/agent/index',
        })
      }
    }
  }
}

export const agentRedirectionMixin = {
  created() {
    const token = uni.getStorageSync('token')
    if (!token) {
      uni.reLaunch({
        url: '/pages/login/login',
      })
    } else {
      const userInfo = uni.getStorageSync('user')
      if (userInfo && userInfo.role !== 1) {
        uni.reLaunch({
          url: '/pages/admin/index',
        })
      }
    }
  },
}
